home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / jdp1_4.zip / JDP1_4.EXE / data.1 / JDPLayout5.java < prev    next >
Text File  |  1996-11-07  |  15KB  |  512 lines

  1. >XXX0500  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.StringTokenizer;
  12. import java.util.Vector;
  13.  
  14.  
  15. >003public class <JDPUserBill> extends JDPClassLayout {
  16.  
  17.     JDPUser user;
  18.     JDPJagg jaggSQL;
  19.     JDPWhereClause jdpWhereClause;
  20.     JDPSearchResults searchResults;
  21.     JDPChart chartPanel;
  22.     JDPChartParms p;
  23.  
  24.     Choice thisChartType;
  25.     Choice thisAutoScale;
  26.     Choice thisAutoZoom;
  27.  
  28.     String[] psortChoice;
  29.     String[] pdisplayChoice;
  30.     int itemIndex;
  31.     boolean insertRequested = false;
  32.     boolean deleteRequested = false;
  33.     String pfromWhereClause;
  34.     String prevSQL = "";
  35.     Color[] colorList = {Color.blue,Color.cyan,Color.green,Color.magenta,Color.orange,
  36.                          Color.red,Color.white,Color.yellow,Color.pink,Color.black,
  37.                          Color.darkGray,Color.gray};
  38.  
  39.     Vector pmatchUsing;
  40.     Vector pactualmatchUsing;
  41.  
  42.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  43.  
  44.         this.user = user;
  45.         //
  46.         //  Set JAGG settings for this class
  47.         //
  48.         jaggSQL = new JDPJagg(user.jaggPath);
  49.         jaggSQL.setNULL("space");
  50. >994        jaggSQL.setMRW("<maxRows>");
  51. >998        jaggSQL.setDSN("<datasource>");
  52. >999        jaggSQL.setCSTR("<connectstr>");
  53.  
  54.         setLayout(new BorderLayout());
  55.         setFont(user.plainFont);
  56.  
  57.         Panel mainPanel = new Panel();
  58.         mainPanel.setLayout(new BorderLayout());
  59.         Panel chartMainPanel = new Panel();
  60.         chartMainPanel.setLayout(new BorderLayout());
  61.         Panel centerPanel = new Panel();
  62.         centerPanel.setLayout(new BorderLayout());
  63.         Panel centerMainPanel = new Panel();
  64.         centerMainPanel.setLayout(new BorderLayout());
  65.         Panel centerTopPanel = new JDPScrollPanel();
  66.         Panel leftPanel = new Panel();
  67.         leftPanel.setLayout(new BorderLayout());
  68.         
  69.         p = new JDPChartParms();
  70. >140        p.chartType = <>;
  71.         thisChartType = new Choice();
  72.         thisChartType.addItem("Column");
  73.         thisChartType.addItem("Bar");
  74.         thisChartType.addItem("Line");
  75.         thisChartType.addItem("Area");
  76.         thisChartType.addItem("Pie");
  77.         thisChartType.select(p.chartType-1);
  78.  
  79. >154        p.autoscale = <>;
  80.         thisAutoScale = new Choice();
  81.         thisAutoScale.addItem("Yes");
  82.         thisAutoScale.addItem("No");
  83.         if (!p.autoscale) thisAutoScale.select("No");
  84. >155        p.autozoom = <>;
  85.          thisAutoZoom = new Choice();
  86.         thisAutoZoom.addItem("Yes");
  87.         thisAutoZoom.addItem("No");
  88.         if (!p.autozoom) thisAutoZoom.select("No");
  89.  
  90.         chartPanel = new JDPChart(user,p);
  91.         chartMainPanel.add("Center",chartPanel);
  92.         mainPanel.add("Center",chartMainPanel);
  93.  
  94.         Panel controlPanel = new Panel();
  95.         controlPanel.setLayout(new JDPLineLayout(3));
  96.         chartMainPanel.add("South",controlPanel);
  97.         controlPanel.add("Left",new JDPWrapLabel(user,"Type:"));
  98.         controlPanel.add("Left",thisChartType);
  99.         controlPanel.add("Left",new JDPWrapLabel(user,"Auto Scale:"));
  100.         controlPanel.add("Left",thisAutoScale);
  101.         controlPanel.add("Left",new JDPWrapLabel(user,"Auto Zoom:"));
  102.         controlPanel.add("Left",thisAutoZoom);
  103.  
  104.         //
  105.         //  Define parameters for JDPSearchResults
  106.         //
  107. >005        String pselectFields = "<>"; String[] psdisplayFields = {<>};
  108. >006        pfromWhereClause = "<FROM JDPUser WHERE >";
  109.  
  110. >007        psortChoice = new String[<5>];
  111. >008        psortChoice[<0>] = "<username>";
  112.  
  113. >009        String[] psortChoiceText = {<"Sort by User Name","Sort by Card Number">};
  114.         pdisplayChoice = psortChoice;
  115.  
  116. >010        boolean pdisplayCount = <true>;
  117. >011        String pcountText = "<Total Entries:>";
  118.     
  119.         //
  120.         //  Define parameters for JDPWhereClause
  121.         //
  122. >016        String[] pchooseFrom = new String[<7>];
  123. >017        pchooseFrom[<0>] = "<Account Name>";
  124.  
  125. >018        String[] pactualchooseFrom = new String[<7>];
  126. >019        pactualchooseFrom[<0>] = "<username>";
  127.  
  128.         loadMatchUsing();
  129.  
  130. >024        boolean[] constantIsString = new boolean[<7>];
  131. >025        constantIsString[<0>] = <true>;
  132.  
  133. >026        int[] constantLength = new int[<7>];
  134. >027        constantLength[<0>] = <20>;
  135.  
  136.         //
  137.         //  Add JDPWhereClause search panel
  138.         //
  139.         boolean verticalPos = false;
  140.         if (psortChoice.length > 0) {
  141.             verticalPos = true;
  142.         }
  143.         if (pchooseFrom.length > 0) {
  144. >028            jdpWhereClause = new JDPWhereClause(user, targetPanel, "<UserBill>", verticalPos, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  145.                                                 pmatchUsing, pactualmatchUsing, null, null,
  146.                                                 constantLength, constantIsString);
  147.             if (psortChoice.length > 0) {
  148.                 leftPanel.add("North",jdpWhereClause);
  149.             } else {
  150.                 mainPanel.add("North",jdpWhereClause);
  151.             }
  152.         }
  153.         //
  154.         //  Add JDPSearchResults result list
  155.         //
  156.         if (psortChoice.length > 0) {
  157. >029            searchResults = new JDPSearchResults(user, targetPanel, <false>, jaggSQL, <false>, pselectFields, psdisplayFields, pfromWhereClause, psortChoiceText, psortChoice, pdisplayChoice, "<pinitChoice>", pdisplayCount, pcountText);
  158. >055            int icons[] = {<>};
  159. >056            searchResults.setMinWidth(<>);
  160.             searchResults.setIcons(icons);
  161.             leftPanel.add("Center",searchResults);
  162.             mainPanel.add("West",leftPanel);
  163.         }
  164.  
  165. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",mainPanel,"North"));
  166.  
  167.         //
  168.         //  Add the handle to this panel to the global vector so other panels can
  169.         //  access this one
  170.         //
  171.         user.gParm.addElement(this);
  172.  
  173.         newSearch();
  174.     }
  175.  
  176.     //
  177.     //  Handle screen events
  178.     //
  179.     public boolean handleEvent(Event e) {
  180.  
  181.         switch (e.id) {
  182.         case Event.ACTION_EVENT:
  183.             if (e.target instanceof List) {
  184.                 if (e.target.equals(searchResults.resultList)) {
  185.                     loadChart();
  186.                     chartPanel.calculateScaling();
  187.                     chartPanel.repaint();
  188.                     return true;
  189.                 }
  190.             }
  191.             if (e.target instanceof JDPTreePicker) {
  192.                 if (e.target.equals(searchResults.tree)) {
  193.                     loadChart();
  194.                     chartPanel.calculateScaling();
  195.                     chartPanel.repaint();
  196.                     return true;
  197.                 }
  198.             }
  199.             if (e.target instanceof Button) {
  200.                 String choice = (String)e.arg;
  201.                 if (choice.trim().compareTo("Search") == 0) {
  202.                     insertRequested = false;
  203.                     deleteRequested = false;
  204.                     newSearch();
  205.                     return true;
  206.                 }
  207.                 return true;
  208.             }
  209.             if (e.target instanceof Choice) {
  210.                 if ((e.target.equals(thisChartType)) ||
  211.                     (e.target.equals(thisAutoScale)) ||
  212.                     (e.target.equals(thisAutoZoom))) {
  213.                     loadChart();
  214.                     chartPanel.calculateScaling();
  215.                     chartPanel.repaint();
  216.                     return true;
  217.                 }
  218.                 return true;
  219.             }
  220.             if (e.target instanceof TextField) {
  221.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  222.                     insertRequested = false;
  223.                     deleteRequested = false;
  224.                     newSearch();
  225.                     return true;
  226.                 }
  227.                 checkFields();
  228.                 return true;
  229.             }
  230.             return false;
  231.  
  232.         case Event.KEY_PRESS:
  233.             if (e.key == '\t') {
  234.                 //  handle tabbing between components
  235.                 if (e.modifiers != Event.SHIFT_MASK) {
  236.                 } else {
  237.                 }
  238.                 return true;
  239.             }
  240.             return false;
  241.  
  242.         case Event.WINDOW_EXPOSE:
  243.             if (e.target instanceof JDPTabSelectPanel) {
  244.                 //
  245.                 //  This is where you place code to get executed when this panel is
  246.                 //  reactivated from the tab menu
  247.                 //
  248.                 return true;
  249.             }
  250.             return false;
  251.  
  252.         default:
  253.             return false;
  254.  
  255.         }
  256.     }
  257.  
  258.     //
  259.     //  Retrieve the handle to another panel so as to be able to interact with it
  260.     //
  261.     public void retrieveHandle() {
  262.  
  263.         for (int ix=0; ix<user.gParm.size(); ix++) {
  264.             //
  265.             //  Activate the next four lines of code to retrieve the handle to another 
  266.             //  Panel within your JDP system. Of course you should declare the variable 
  267.             //  at the top of this source instead of within this method so you can 
  268.             //  access it from all the methods within this class. You only need to 
  269.             //  substitute DemoClass with the name ouf your class. You should call this 
  270.             //  method from somewhere else in this class. To access a variable from 
  271.             //  your resulting class use:
  272.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  273.             //
  274. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  275. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  276. //                return;
  277. //            }
  278.         }
  279.     }
  280.  
  281.     //
  282.     //  The search button was pressed so rerun the query with the new search criteria
  283.     //
  284.     public void newSearch() {
  285.  
  286.         if (psortChoice.length > 0) {
  287.             String whereClause;
  288.  
  289.             whereClause = pfromWhereClause;
  290.             if (jdpWhereClause != null) {
  291.                 whereClause = whereClause + " AND " + jdpWhereClause.whereClause;
  292.             }
  293.             searchResults.setFromWhereClause(whereClause);
  294. >057            searchResults.clearList(<>);
  295.             searchResults.loadList();
  296.         } else {
  297.             loadChart();
  298.             chartPanel.calculateScaling();
  299.             chartPanel.repaint();
  300.         }
  301.     }
  302.  
  303.     //
  304.     //  Load the selected item
  305.     //
  306.     public void loadData() {
  307.  
  308.         StringTokenizer stok;
  309.         int recCount = 0;
  310.         Vector results = new Vector();
  311.         String sep = user.jaggSQL.getSEP();
  312.         int actualRows = 0;
  313.         String row;
  314.         String whereClause = "(1=1)";
  315.  
  316.         if (psortChoice.length > 0) {
  317.             if ((itemIndex = searchResults.getSelectedIndex()) < 0) {
  318.                 clearFields();
  319.                 return;
  320.             }
  321.         }
  322.         
  323.         if (jdpWhereClause != null) whereClause = jdpWhereClause.whereClause;
  324.  
  325. >130        int groupCount = <>;
  326. >131        int seriesCount = <>;
  327.  
  328. >132        String SQL = "<SELECT >";
  329.  
  330.  
  331.         prevSQL = SQL;
  332.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  333.  
  334.         recCount = jaggSQL.execSQL(SQL, results);
  335.  
  336.         if(recCount == -1) {
  337.             user.u.setSqlMessage(jaggSQL,SQL);
  338.             return;
  339.         }
  340.         //
  341.         //  Initialise result arrays
  342.         //
  343.         int columnCount = jaggSQL.getColumnCount();
  344.         actualRows = jaggSQL.getRowCount();
  345.  
  346.         if (seriesCount <= 0) {
  347.             p.chartData = new float[columnCount-groupCount][actualRows];
  348.             p.xaxisLabel = new String[actualRows];
  349.             p.piechartData = new float[actualRows];
  350.             p.pieSplitSegment = new boolean[actualRows];
  351.             p.pieLabel = new String[actualRows];
  352.             if (p.chartType == JDPChart.PIE) {
  353.                 p.elementColor = new Color[actualRows];
  354.                 p.elementBorderColor = new Color[actualRows];
  355.                  p.elementLegend = new String[actualRows];
  356.             }
  357.             for (int ix=0; ix<actualRows; ix++) {
  358.                 row = (String)results.elementAt(ix);
  359.                 stok = new StringTokenizer(row);
  360.                 p.xaxisLabel[ix] = "";
  361.                 if (groupCount > 0) p.xaxisLabel[ix] = stok.nextToken(sep).trim();
  362.                 for (int iz=0; iz<columnCount-groupCount; iz++) {
  363.                     p.chartData[iz][ix] = Float.valueOf(stok.nextToken(sep).trim()).floatValue();
  364.                 }
  365.                 p.pieLabel[ix] = p.xaxisLabel[ix];
  366.                 p.piechartData[ix] = p.chartData[0][ix];
  367.                 if (p.chartType == JDPChart.PIE) {
  368.                     p.elementColor[ix] = colorList[ix%12];
  369.                     p.elementBorderColor[ix] = Color.black;
  370.                      p.elementLegend[ix] = p.pieLabel[ix];
  371.                 }
  372.             }
  373.         } else {
  374.             float[][] tempchartData = new float[1000][actualRows];
  375.             p.xaxisLabel = new String[actualRows];
  376.             Vector group = new Vector();
  377.             if (groupCount == 0) group.addElement("");
  378.             Vector series = new Vector();
  379.             for (int ix=0; ix<actualRows; ix++) {
  380.                 row = (String)results.elementAt(ix);
  381.                 stok = new StringTokenizer(row);
  382.                 p.xaxisLabel[ix] = "";
  383.                 int groupIndex = 0;
  384.                 if (groupCount > 0) {
  385.                     String groupValue = stok.nextToken(sep).trim();
  386.                     groupIndex = group.indexOf(groupValue);
  387.                     if (groupIndex < 0) {
  388.                         group.addElement(groupValue);
  389.                         groupIndex = group.indexOf(groupValue);
  390.                         p.xaxisLabel[groupIndex] = groupValue;
  391.                     }
  392.                 }
  393.                 String seriesValue = stok.nextToken(sep).trim();
  394.                 int seriesIndex = series.indexOf(seriesValue);
  395.                 if (seriesIndex < 0) {
  396.                     series.addElement(seriesValue);
  397.                     seriesIndex = series.indexOf(seriesValue);
  398.                 }
  399.                 tempchartData[seriesIndex][groupIndex] = Float.valueOf(stok.nextToken(sep).trim()).floatValue();
  400.             }
  401.  
  402.             int numbars = series.size();
  403.             p.chartData = new float[numbars][group.size()];
  404.             for (int ix=0; ix<numbars; ix++) {
  405.                 for (int iy=0; iy<group.size(); iy++) {
  406.                     p.chartData[ix][iy] = tempchartData[ix][iy];
  407.                 }
  408.             }
  409.             p.elementColor = new Color[numbars];
  410.             p.elementBorderColor = new Color[numbars];
  411.              p.elementLegend = new String[numbars];
  412.             for (int ix=0; ix<numbars; ix++) {
  413.                 p.elementColor[ix] = colorList[ix%12];
  414.                 p.elementBorderColor[ix] = Color.black;
  415.                  p.elementLegend[ix] = (String)series.elementAt(ix);
  416.             }
  417.         }
  418.         user.mainmsg.clearStatusMsg();
  419.     }
  420.  
  421.  
  422.     //
  423.     //  Clear the screen fields for a new option
  424.     //
  425.     public void clearFields() {
  426.  
  427.     }
  428.  
  429.     //
  430.     //  Load all of the Screen Choices
  431.     //
  432.     public void loadChoices() {
  433.  
  434.     }
  435.  
  436.     //
  437.     //  Perform component validations
  438.     //
  439.     public boolean checkFields() {
  440.  
  441.         return true;
  442.  
  443.     }
  444.  
  445.     //
  446.     //  Load the parameters for the selected chart
  447.     //
  448.     public void loadChart() {
  449.  
  450.         p.chartType = thisChartType.getSelectedIndex()+1;
  451.         p.autoscale = thisAutoScale.getSelectedItem().equals("Yes");
  452.         p.autozoom = thisAutoZoom.getSelectedItem().equals("Yes");
  453.  
  454. >141        p.chartTitle = "<>";
  455.         p.chartTitleFont = user.boldFont.getName();
  456. >142        p.chartTitleColor = user.u._cvtcolor("<>");
  457.  
  458. >143        p.xaxisTitle = "<>";
  459.         p.xaxisTitleFont = user.boldFont.getName();
  460. >144        p.xaxisTitleColor = user.u._cvtcolor("<>");
  461.  
  462.         p.yaxisLabel = new String[10];
  463.  
  464.         p.elementLegendFont = user.boldFont.getName();
  465.  
  466. >145        p.xaxisLabelColor = user.u._cvtcolor("<>");
  467. >146        p.yaxisLabelColor = user.u._cvtcolor("<>");
  468. >147        p.chartFrameColor = user.u._cvtcolor("<>");
  469.  
  470. >148        p.elementLegend = new String[<>];
  471. >148        p.elementColor = new Color[<>];
  472. >148        p.elementBorderColor = new Color[<>];
  473. >149        p.elementLegend[<iy>] = "<selectChartDef.elementLegend[ix]>";
  474. >150        p.elementColor[<iy>] = user.u._cvtcolor("<>");
  475. >151        p.elementBorderColor[<iy>] = user.u._cvtcolor("<selectChartDef.elementBorderColor[ix]>");
  476.  
  477. >152        p.gridLineSetting = <JDPChart.HORIZONTAL + JDPChart.VERTICAL + JDPChart.FOREGROUND + JDPChart.BACKGROUND>;
  478. >153        p.gridColor = user.u._cvtcolor("<>");
  479.  
  480. >156        p.maxPlotValue = <>;
  481. >157        p.minPlotValue = <>;
  482.  
  483.         if ((p.chartType == JDPChart.COLUMN) || (p.chartType == JDPChart.BAR) ||
  484.             (p.chartType == JDPChart.AREA)) {
  485.             p.autozoom = false;
  486.         }
  487.  
  488.         p.pieLabel = p.elementLegend;
  489.         p.pieLabelColor = p.xaxisTitleColor;
  490.  
  491.         loadData();
  492.  
  493.  
  494.     }
  495.  
  496.     //
  497.     //  Load the Search Layout pulldown choices
  498.     //
  499.     public void loadMatchUsing() {
  500.  
  501.         pmatchUsing = new Vector();
  502.         pactualmatchUsing = new Vector();
  503. >020        pmatchUsing.addElement(new Vector());
  504. >022        pactualmatchUsing.addElement(new Vector());
  505. >021        ((Vector)pmatchUsing.elementAt(<0>)).addElement("<Begins with>");
  506. >023        ((Vector)pactualmatchUsing.elementAt(<0>)).addElement("< like >");
  507.  
  508.     }
  509.  
  510.  
  511. }
  512.